const { model, Schema } = require('mongoose');

//level: 0(超级管理员) 1(普通管理员)
const adminSchema = new Schema({
  avatar: String,
  username: String,
  password: String,
  level: Number,
}, {
  timestamps: true,
  versionKey: false
});

// 用户
const userSchema = Schema({
  username: String,
  password: String,
  avatar: String, // 头像
}, {
  timestamps: true,
  versionKey: false
})

// 商品
const goodsSchema = Schema({
  name: String,
  describe: String,//商品描述
  count: Number,//浏览次数
  price: Number,//价格
  fineness:  String,//商品成色
  img:  String,
  classify:  String,//商品分类
  user_id: { type: Schema.Types.ObjectId, ref: 'users' },
}, {
  timestamps: true,
  versionKey: false
})

// 分类
const classifySchema = Schema(
  {
    class1: String,
    class2: String,
    class3: String,
    class4: String,
    class5: String,
  })

// 成色
const finenessSchema = Schema({
  type1: String,
  type2: String,
  type3: String,
  type4: String,
}, {
  timestamps: true,
  versionKey: false
})

// 头像
const imgSchema = new Schema({
  path: String,
}, {
  timestamps: true,
  versionKey: false
})

const adminModel = model("admins", adminSchema);

const userModel = model('users', userSchema);

const goodsModel = model('goods', goodsSchema);

const imgModel = model("imgs", imgSchema);

const finenessModel = model("fineness", finenessSchema);

const classifyModel = model('classify', classifySchema)




module.exports = { adminModel, userModel, goodsModel, imgModel, finenessModel, classifyModel };